
#Region "Using Directives"

Imports System.Collections.Generic
Imports System

#End Region

Namespace C4F.DevKit.Bluetooth.ObjectPushProfile

    ''' <summary>
    ''' Abstract class to verify object types. This class should be implemented
    ''' to create a type verifier.
    ''' </summary>
    Public MustInherit Class ObjectTypeVerifier

#Region "Private Fields"

        ''' <summary>
        ''' The list of objectTypes supported by the ObjectTypeVerifier.
        ''' </summary>
        Private objectTypes As List(Of String)

#End Region

#Region "Constructors"

        ''' <summary>
        ''' Initializes the type verifier.
        ''' </summary>
        Protected Sub New()

            objectTypes = New List(Of String)()

        End Sub

#End Region

#Region "Public Functions/Methods"

        ''' <summary>
        ''' Overridable method for checking the type of the object received.
        ''' All types that will be verified by this verifier should be added to
        ''' the list of object types. This method should contain type checking
        ''' code against all types mentioned in the list. If a type mismatch 
        ''' occurs, an OPPTypeMismatchException should be thrown. In case the
        ''' provided type is not supported, an ArgumentException should be 
        ''' thrown.
        ''' </summary>
        ''' <param name="dataReceived">The byte array to be verified.</param>
        ''' <param name="typeExpected">The type against which the passed object
        ''' needs to be verified.</param>
        ''' <exception cref="ArgumentException">The provided type is not present
        ''' in the list of internally maintained object types.</exception>
        ''' <exception cref="OPPTypeMismatchException">The type of data 
        ''' received is not of the expected type.</exception>
        Public MustOverride Sub VerifyType(ByVal dataReceived() As Byte, ByVal typeExpected As String)

        ''' <summary>
        ''' Returns true if the specified object type is present in the list of
        ''' object types that will be verified when a call to VerifyType() is
        ''' made.
        ''' </summary>
        ''' <param name="objectType">A string value whose existence is to be 
        ''' checked in the list of object types supported by this type verifier.
        ''' </param>
        ''' <returns>A value indicating whether the object type is supported by
        ''' the type verifier.</returns>
        ''' <exception cref="ArgumentNullException">ObjectType is empty or
        ''' passed as a null reference.</exception>
        Public Function IsObjectTypeSupported(ByVal objectType As String) As Boolean

            If String.IsNullOrEmpty(objectType) Then
                Throw New ArgumentNullException("objectType")
            End If

            If Me.objectTypes.Contains(objectType) Then
                Return True
            Else
                Return False
            End If

        End Function

#End Region

#Region "Protected Functions/Methods"

        ''' <summary>
        ''' Adds an object type to the list of object types that will be 
        ''' verified when a call to VerifyType() is made.
        ''' </summary>
        ''' <param name="objectType">The object type to be added.</param>
        ''' <exception cref="ArgumentNullException">objectType is empty or
        ''' passed as a null reference.</exception>
        ''' <exception cref="ArgumentException">objectType already exists in
        ''' the internal list of object types supported by the type verifier.
        ''' </exception>
        Protected Sub AddObjectType(ByVal objectType As String)

            If String.IsNullOrEmpty(objectType) Then
                Throw New ArgumentNullException("objectType")
            End If

            If Me.objectTypes.Contains(objectType) Then
                Throw New ArgumentException(OPPResources.Error_ObjectTypeExists, "objectType")
            End If

            Me.objectTypes.Add(objectType)

        End Sub

        ''' <summary>
        ''' Removes an object type from the list of object types that will be
        ''' verified when a call to VerifyType() is made.
        ''' </summary>
        ''' <param name="objectType">The object type to be removed.</param>
        ''' <exception cref="ArgumentNullException">ObjectType is empty or
        ''' passed as a null reference.</exception>
        ''' <exception cref="ArgumentException">ObjectType does not exist in
        ''' the internal list of object types supported by the type verifier.
        ''' </exception>
        Protected Sub RemoveObjectType(ByVal objectType As String)

            If String.IsNullOrEmpty(objectType) Then
                Throw New ArgumentNullException("objectType")
            End If

            If Not Me.objectTypes.Contains(objectType) Then
                Throw New ArgumentException(OPPResources.Error_ObjectTypeDoesNotExist, "objectType")
            End If

            Me.objectTypes.Remove(objectType)

        End Sub

        ''' <summary>
        ''' Method for getting the object types that will be verified when a
        ''' call to VerifyType() is made.
        ''' </summary>
        ''' <returns>String array of the object types supported by the type
        ''' verifier.</returns>
        Protected Function GetSupportedObjectTypes() As String()

            Return Me.objectTypes.ToArray()

        End Function

#End Region

    End Class

End Namespace
